﻿using Xejen.Communication.Endpoints;
using Xejen.Communication.Socket.Communicator;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Xejen.Communication.Socket.Client.Test
{
    public class Service
    {
        private readonly ISocketCommunicator _communicator;
        private readonly IConfiguration _configuration;
        //public Service(ISocketCommunicator communicator, IConfiguration configuration)
        //{
        //    _communicator = communicator;
        //    _configuration = configuration;
        //}

        public Service(IEnumerable<ISocketCommunicator> communicators, IConfiguration configuration)
        {
            _communicator = communicators.First(q => q.CurrentConnection.ServerAddress == "127.0.0.1");
            _configuration = configuration;
        }

        public async Task ExecuteAsync()
        {
            //Addresses addresses = new Addresses();
            //_configuration.Bind(addresses);
            //var result1 = await _communicator.RequestAsync(SocketAddressWrapper.Create(addresses.GetWeatherForecast));



            //var address = new SocketAddressWrapper()
            //{
            //    RequestAddress = SocketAddress.Empty,
            //};

            //byte[] bytes = _communicator.Config.Encoding.GetBytes(JsonSerializer.Serialize("fdsa哈根达斯魂牵梦萦人斯柯达  魂牵梦萦为Q@$(*$1硒鼓", _communicator.Config.JsonSerializerOptions));

            //var bytes22 = _communicator.Config.Encoding.GetBytes(JsonSerializer.Serialize(bytes, _communicator.Config.JsonSerializerOptions));

            //var s1 = _communicator.Config.Encoding.GetString(bytes22);

            //var result1 = await _communicator.SendAsync(address, bytes);
            //MessageBox.Show(result1.ToString());




            SocketResponse result1 = await _communicator.SendAsync("fdsa哈根达斯魂牵梦萦人斯柯达  魂牵梦萦为Q@$(*$1硒鼓");
            MessageBox.Show(result1.ToString());
        }
    }
}
